<?php
/**
 * Custom API function to get clients domains
 * @author David Majchrzak www.visions.se 2011-04-02
 */
 
if (preg_match('/^\d+$/',$_POST['clientid'])) {
 
    $result = mysql_query("SELECT * FROM tbldomains WHERE userid='".
                          $_POST['clientid']."'");
    $amount = mysql_num_rows($result);
 
    $xml = null;
 
 
    $xml .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xml .= "<whmcsapi version=\"4.4.2\">\n";
    $xml .= "    <action>getclientsdomains</action>\n";
    $xml .= "    <result>success</result>\n";
    $xml .= "    <totalresults>".$amount."</totalresults>\n";
 
    if($amount !== 0)
    {
        $xml .= "    <domains>\n";
 
        while($row = mysql_fetch_array($result))
        {
            $xml .= "        <domain>\n";
            $xml .= "            <id>".$row['id']."</id>\n";
            $xml .= "            <userid>".$row['userid']."</userid>\n";
            $xml .= "            <orderid>".$row['orderid']."</orderid>\n";
            $xml .= "            <type>".$row['type']."</type>\n";
            $xml .= "            <regdate>".$row['registrationdate']."</regdate>\n";
            $xml .= "            <name>".$row['domain']."</name>\n";
            $xml .= "            <firstpaymentamount>".$row['firstpaymentamount']."</firstpaymentamount>\n";
            $xml .= "            <recurringamount>".$row['recurringamount']."</recurringamount>\n";
            $xml .= "            <registrar>".$row['registrar']."</registrar>\n";
            $xml .= "            <registrationperiod>".$row['registrationperiod']."</registrationperiod>\n";
            $xml .= "            <expirydate>".$row['expirydate']."</expirydate>\n";
            $xml .= "            <subscriptionid>".$row['subscriptionid']."</subscriptionid>\n";
            $xml .= "            <promoid>".$row['promoid']."</promoid>\n";
            $xml .= "            <status>".$row['status']."</status>\n";
            $xml .= "            <nextduedate>".$row['nextduedate']."</nextduedate>\n";
            $xml .= "            <nextinvoicedate>".$row['nextinvoicedate']."</nextinvoicedate>\n";
            $xml .= "            <additionalnotes><![CDATA[".$row['additionalnotes']."]]></additionalnotes>\n";
            $xml .= "            <paymentmethod>".$row['paymentmethod']."</paymentmethod>\n";
            $xml .= "            <dnsmanagement>".$row['dnsmanagement']."</dnsmanagement>\n";
            $xml .= "            <emailforwarding>".$row['emailforwarding']."</emailforwarding>\n";
            $xml .= "            <idprotection>".$row['idprotection']."</idprotection>\n";
            $xml .= "            <donotrenew>".$row['donotrenew']."</donotrenew>\n";
            $xml .= "        </domain>\n";
        }
 
        $xml .= "    </domains>\n";
    }
 
    $xml .= "</whmcsapi>";
 
    echo $xml;   
} else {
 
    $xml = null;
 
    $xml .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xml .= "<whmcsapi version=\"4.4.2\">\n";
    $xml .= "    <action>getclientsdomains</action>\n";
    $xml .= "    <result>error</result>\n";
    $xml .= "    <message>Invalid argument supplied</message>\n";
    $xml .= "</whmcsapi>\n";
 
    echo $xml;
 
}
?>